package com.blu.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.blu.utils.Md5Util;

@Controller
public class LoginController {
	
	@GetMapping("login")
	public String toLoginPage(Model model) {
		return "login";
	}
	
	@PostMapping("doLogin")
	public String doLogin(@RequestParam String username, @RequestParam String password, HttpSession session) {
		if("blu".equals(username)&&"a7873113f83ce292".equals(Md5Util.getMd5String(Md5Util.getMd5String(password)))) {
			session.setAttribute("user-name", username);
			return "redirect:/";
		}
		if("yangyin".equals(username)&&"80b43f83fb624c2b".equals(Md5Util.getMd5String(Md5Util.getMd5String(password)))) {
			session.setAttribute("user-name", username);
			return "redirect:/";
		}
		return "redirect:/login";
	}
	
}
